#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2021/8/9 16:51
# @Author  : Samge
from functools import lru_cache
from itkz.spider_ext import settings


@lru_cache()
def add_splash_tag(url):
    """往url链接中添加splash标签"""
    if not url:
        return url
    return f'{url}&{settings.SPLASH_TAG}' if '?' in url else f'{url}?{settings.SPLASH_TAG}'


@lru_cache()
def remove_splash_tag(url):
    """移除链接中的splash标签"""
    if not url:
        return url
    return url.replace(f'?{settings.SPLASH_TAG}', '').replace(f'&{settings.SPLASH_TAG}', '')


@lru_cache()
def is_splash(url):
    """是否使用splash进行请求"""
    if not url:
        return False
    return settings.SPLASH_TAG in url